//
//  NSString+Verify.m
//  XYZKitDemo
//
//  Created by 谢英泽 on 2016/11/20.
//  Copyright © 2016年 谢英泽. All rights reserved.
//

#import "NSString+Verify.h"

@implementation NSString (Verify)

/**
 是否是昵称格式
 */
+ (BOOL)verifyNikeName:(NSString *)string
{
    //字母、数字、中文正则判断（不包括空格）
    NSString * regex = @"^[a-zA-Z\u4E00-\u9FA5\\d]*$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [pred evaluateWithObject:string];
}

/**
 是否为纯汉字
 */
+ (BOOL)verifyChineseCharacters:(NSString *)string
{
    NSString * regex = @"^[\u4e00-\u9fa5]{0,}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [pred evaluateWithObject:string];
}

/**
 是否为纯数字
 */
+ (BOOL)verifyNumber:(NSString *)string
{
    NSString * regex = @"^[0-9]*$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [pred evaluateWithObject:string];
}

/**
 是否为密码格式
 密码必须为6~16位,由字母和数字组成
 */
+ (BOOL)verifyPassword:(NSString *)password
{
    NSString * regex = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [pred evaluateWithObject:password];
}

/**
 是否为银行卡格式
 是否银行卡 (16~19位纯数字)
 */
+ (BOOL)verifyBankCardNum:(NSString *)string
{
    NSString * regex = @"^\\d{15,22}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [pred evaluateWithObject:string];
}

/**
 手机号码格式
 */
+ (BOOL)verifyPhone:(NSString *)phone
{
    NSString * regex = @"^((13[0-9])|(15[0-9])|(18[0-9]|(14[0-9])|(17[0-9])))\\d{8}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [pred evaluateWithObject:phone];
    
    //NSString *mobileNoRegex = @"^1((3\\d|5[0-35-9]|8[025-9])\\d|70[059])\\d{7}$";
    //NSString *phsRegex =@"^0(10|2[0-57-9]|\\d{3})\\d{7,8}$";
    
    //NSPredicate *pre1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",mobileNoRegex];
    //NSPredicate *pre2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phsRegex];
    
    //BOOL ret = [pre1 evaluateWithObject:phone];
    //BOOL ret1 = [pre2 evaluateWithObject:phone];
    //return (ret || ret1);
}

/**
 是否纯数字和字母
 */
+ (BOOL)verifyNumberAndLetter:(NSString *)string
{
    NSString * regex = @"^[A-Za-z0-9]*$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [pred evaluateWithObject:string];
}

@end
